In [ ]:
from __future__ import print_function
import msaf
import librosa
import seaborn as sns
# and IPython.display for audio output
import IPython.display
# Setup nice plots
sns.set(style="dark")
%matplotlib inline
In [ ]:
# Choose an audio file and listen to it
audio_file = "../datasets/Sargon/audio/01-Sargon-Mindless.mp3"
IPython.display.Audio(filename=audio_file)
In [33]:
# Segment the file using the default MSAF parameters
boundaries, labels = msaf.process(audio_file)
print(boundaries)
In [ ]:
# Sonify boundaries
sonified_file = "my_boundaries.wav"
sr = 44100
boundaries, labels = msaf.process(audio_file, sonify_bounds=True,
out_bounds=sonified_file, out_sr=sr)
# Listen to results
audio = librosa.load(sonified_file, sr=sr)[0]
IPython.display.Audio(audio, rate=sr)
MSAF includes multiple algorithms both for boundary retrieval and structural grouping (or labeling). In this section we demonstrate how to try them out.
Note: more algorithms are available in msaf-gpl.
In [34]:
# First, let's list all the available boundary algorithms
print(msaf.get_all_boundary_algorithms())
In [35]:
# Try one of these boundary algorithms and print results
boundaries, labels = msaf.process(audio_file, boundaries_id="foote", plot=True)
In [36]:
# Let's check all the structural grouping (label) algorithms available
print(msaf.get_all_label_algorithms())
In [37]:
# Try one of these label algorithms
boundaries, labels = msaf.process(audio_file, boundaries_id="foote", labels_id="fmc2d")
print(boundaries)
print(labels)
In [38]:
# If available, you can use previously annotated boundaries and a specific labels algorithm
# Set plot = True to plot the results
boundaries, labels = msaf.process(audio_file, boundaries_id="gt",
labels_id="scluster", plot=True)
In [39]:
# Let's check what available features are there in MSAF
print(msaf.AVAILABLE_FEATS)
In [40]:
# Segment the file using the Foote method for boundaries, C-NMF method for labels, and MFCC features
boundaries, labels = msaf.process(audio_file, feature="mfcc", boundaries_id="foote",
labels_id="cnmf", plot=True)
In [41]:
# Evaluate the results. It returns a pandas data frame.
evaluations = msaf.eval.process(audio_file, boundaries_id="foote", labels_id="fmc2d")
IPython.display.display(evaluations)
In [42]:
# First, check which are foote's algorithm parameters:
print(msaf.algorithms.foote.config)
In [43]:
# play around with IPython.Widgets
from IPython.html.widgets import interact
# Obtain the default configuration
bid = "foote" # Boundaries ID
lid = None # Labels ID
feature = "hpcp"
config = msaf.io.get_configuration(feature, annot_beats=False, framesync=False,
boundaries_id=bid, labels_id=lid)
# Sweep M_gaussian parameters
@interact(M_gaussian=(50, 500, 25))
def _run_msaf(M_gaussian):
# Set the configuration
config["M_gaussian"] = M_gaussian
# Segment the file using the Foote method, and Pitch Class Profiles for the features
results = msaf.process(audio_file, feature=feature, boundaries_id=bid,
config=config, plot=True)
# Evaluate the results. It returns a pandas data frame.
evaluations = msaf.eval.process(audio_file, feature=feature, boundaries_id=bid,
config=config)
IPython.display.display(evaluations)
In [44]:
dataset = "../datasets/Sargon/"
results = msaf.process(dataset, n_jobs=4, boundaries_id="foote")
In [45]:
# Evaluate in collection mode
evaluations = msaf.eval.process(dataset, n_jobs=4, boundaries_id="foote")
IPython.display.display(evaluations)